const http = require("http");
const fs = require("fs");
const path = require("path");

var filePath = path.join(__dirname, "/data.json");

var data = fs.readFileSync(filePath);
var dataStr = data.toString();
var userObj = JSON.parse(dataStr);
var userList = userObj.userList;

http.createServer((req,res)=>{
    var str = "";
    req.on("data", (chunk)=>{
        str += chunk;
    })
    req.on("end", ()=>{
        var obj = JSON.parse(str);
        for(var i = 0; i<userList.length+1; i++){
            if(i < userList.length){
                if(obj.userName == userList[i].userName && obj.pwd == userList[i].pwd){
                    console.log("登录成功！");
                    break;
                }
            }else{
                console.log("用户名、密码不正确")
            }
        }
    })
}).listen(8081)